package com.jlkf.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jlkf.dao.TblUserWithdrawMapper;
import com.jlkf.pojo.TblOrder;
import com.jlkf.pojo.TblUserWithdraw;
import com.jlkf.service.ContentService;
import com.jlkf.service.OrderService;
import com.platform.server.response.response.pojo.ReturnData;
import com.platform.server.util.StringTools;

@Controller
@RequestMapping("order")
public class OrderController {
	@Autowired
	private OrderService orderService;
	@Autowired
	private ContentService contentService;
	@Autowired
	private TblUserWithdrawMapper tblUserWithdrawMapper;
	
	/**
	 * 订单列表
	 * @param startTime
	 * @param endTime
	 * @param type
	 * @param status
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("getListByType")
	@ResponseBody
	public ReturnData getListByType(String startTime,String endTime,Integer type,Integer status,Integer pageNumber,Integer pageSize){
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("type", type);
		if(!StringTools.isEmpty(startTime)){
			map.put("startTime", startTime);
		}
		if(!StringTools.isEmpty(endTime)){
			map.put("endTime", endTime);
		}
		if(status!=null){
			map.put("status", status);
		}
		PageHelper.startPage(pageNumber, pageSize);
		List<TblOrder> list = orderService.getListByType(map);
		PageInfo<TblOrder> pageInfo = new PageInfo<TblOrder>(list);
		return new ReturnData(list,pageInfo.getPages(),(int)pageInfo.getTotal(),200,"订单列表");
	}
	
	/**
	 * 订单列表
	 * @param startTime
	 * @param endTime
	 * @param type
	 * @param status
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("getVipStatistics")
	@ResponseBody
	public ReturnData getVipStatistics(String startTime,String endTime,String vipName,String education,Integer payType,Integer pageNumber,Integer pageSize){
		Map<String, Object> map = new HashMap<String,Object>();
		if(!StringTools.isEmpty(startTime)){
			map.put("startTime", startTime);
		}
		if(!StringTools.isEmpty(endTime)){
			map.put("endTime", endTime);
		}
		if(!StringTools.isEmpty(vipName)){
			map.put("vipName", vipName);
		}
		if(!StringTools.isEmpty(education)){
			map.put("education", education);
		}
		if(payType!=null){
			map.put("payType", payType);
		}
		PageHelper.startPage(pageNumber, pageSize);
		List<TblOrder> list = orderService.getVipStatistics(map);
		PageInfo<TblOrder> pageInfo = new PageInfo<TblOrder>(list);
		return new ReturnData(list,pageInfo.getPages(),(int)pageInfo.getTotal(),200,"会员缴费统计");
	}
	
	/**
	 * 提现统计
	 * @param startTime
	 * @param endTime
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("withdrawStatistics")
	@ResponseBody
	public ReturnData withdrawStatistics(String startTime,String endTime,Integer pageNumber,Integer pageSize){
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("status", 5);
		if(!StringTools.isEmpty(startTime)){
			map.put("startTime", startTime);
		}
		if(!StringTools.isEmpty(endTime)){
			map.put("endTime", endTime);
		}
		PageHelper.startPage(pageNumber, pageSize);
		List<TblUserWithdraw> list = contentService.selectList(map);
		PageInfo<TblUserWithdraw> pageInfo = new PageInfo<TblUserWithdraw>(list);
		Map<String, Object> map2 = new HashMap<String,Object>();
		map2.put("list", list);
		map2.put("peopleNum", tblUserWithdrawMapper.selectPeopleNum());
		map2.put("totalMoney", tblUserWithdrawMapper.selectWithdrawTotal());
		return new ReturnData(map2,pageInfo.getPages(),(int)pageInfo.getTotal(),200,"提现统计");
	}
}
